<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="utf-8">
  <title>添加任务</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" th:href="@{/static/layuiadmin/layui/css/layui.css}" media="all">
  <link rel="stylesheet" th:href="@{/static/layuiadmin/style/admin.css}" media="all">
</head>
<body>
  <div class="layui-form" lay-filter="sys-task-form" id="sys-task-form"  style="padding: 20px 0 0 0;">
    <div class="layui-form-item">
      <label class="layui-form-label">名称</label>
      <div class="layui-input-inline">
        <input type="text" name="name" lay-verify="required" placeholder="请输入名称" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">表达式</label>
      <div class="layui-input-inline">
        <input id="cron" type="text" name="cron" lay-verify="required" placeholder="请输入表达式" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">类名称</label>
      <div class="layui-input-inline">
        <input type="text" name="className" lay-verify="required" placeholder="请输入类名称" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">方法名</label>
      <div class="layui-input-inline">
        <input type="text" name="methodName" lay-verify="required" placeholder="请输入方法名" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">状态</label>
      <div class="layui-input-block" id="enabled"></div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">备注</label>
      <div class="layui-input-inline">
        <input type="text" name="remark" placeholder="请输入备注" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item layui-hide">
      <input type="button" lay-submit lay-filter="save-submit" id="save-submit" value="确认">
    </div>
  </div>

  <script th:src="@{/static/layuiadmin/layui/layui.js}"></script>
  <script th:inline="javascript">
  let ctx = [[${#request.getContextPath()}]];
  layui.config({
      base: '/static/layuiadmin/' //静态资源所在路径
  }).extend({
     index: 'lib/index', //主入口模块
  }).use(['index', 'form','crud'], function(){
    let $ = layui.$
        ,crud = layui.crud
        ,form = layui.form;
    form.on('submit(save-submit)', function(data){
          $.ajax({
              type: 'POST',
              url:  ctx + '/sysTask/add',
              data: JSON.stringify(data.field),
              contentType:'application/json;charset=UTF-8',
              dataType: 'json',
              success: function(result) {
                  layer.msg(result.message);
                  if (result.code === 200) {
                      let index = parent.layer.getFrameIndex(window.name);
                      // 关闭
                      parent.layer.close(index);
                      // 刷新
                      parent.location.reload();
                  }
              }
          });
    });
    crud.setRadio("enabled","enabled","Y");

    $('#cron').on('click', function(){
      layer.open({
        type: 2,
        title: "Cron表达式生成器",
        content: ctx + '/sysTask/cronPage'
        ,maxmin: true
        ,area: ['500px', '450px']
        ,btn: ['确定', '取消']
        ,yes: function(index, layero) {
          let iframeWin = window[layero.find('iframe')[0]['name']];
          let cron = iframeWin.document.getElementById("cron").value;
          $("#cron").val(cron);
          layer.close(index);
        }
      });
    });
  });
  </script>
</body>
</html>